package cn.wolfcode.trip.admin.filter;




import org.apache.commons.io.FileUtils;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;

public class BeforeImagesFilter implements Filter {


    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        File file = new File("D:/trip/upload", req.getRequestURI());
        if(file.exists()){
            response.getOutputStream().write(FileUtils.readFileToByteArray(file));
            return;
        }
        chain.doFilter(request,response);

    }

    @Override
    public void destroy() {

    }
}
